package com.sunnada.demo.log.controller;

import com.sunnada.demo.common.PagerItem;
import com.sunnada.demo.log.bean.TrackLog;
import com.sunnada.demo.log.service.TrackLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: mybatisproject2
 * @description: 操作日志
 * @author: 李瑞益
 * @create: 2018-11-01 14:40
 **/
@Controller
@RequestMapping("/TrackLog")
public class TrackLogController extends PageController{

    @Autowired
    private TrackLogService trackLogService;

    @RequestMapping("/findAll")
    public String findAll(String name, String operationType,PagerItem pagerItem, HttpServletRequest request){
        Page<TrackLog> Page = trackLogService.findByTime(pagerItem.getPageNum().intValue(), pagerItem.getPageSize().intValue(), name, operationType);
        this.setPage(Page.getTotalElements(), pagerItem, request);
        request.setAttribute("DataList",Page.getContent());
        return "log/track-log";
    }

    /**
     * 完整的查询
     * @param pagerItem
     * @param startTime
     * @param endTime
     * @param request
     * @return
     */
    @RequestMapping("/findAll2")
    public String findAll2(String name, String operationType,PagerItem pagerItem, String startTime,String endTime,HttpServletRequest request){
        TrackLog trackLog = new TrackLog();
        trackLog.setUserName(name);
        trackLog.setOperationType(operationType);
        Page<TrackLog> Page = trackLogService.find(pagerItem.getPageNum().intValue(), pagerItem.getPageSize().intValue(), trackLog,startTime,endTime);
        this.setPage(Page.getTotalElements(), pagerItem, request);
        request.setAttribute("DataList",Page.getContent());
        return "log/track-log";
    }


    @RequestMapping("/findOne")
    public String findOne(String id, Model model){
        TrackLog one = trackLogService.findOne(id);
        model.addAttribute("Data",one);
        return "log/track-log-detail";
    }

}
